<?php
		if(true){
		//page_1
			if ($_GET['page']) {
				$page = $_GET['page'];
				if(is_numeric($page)){
				}else{
					$page = 1;
				}
			} else {
				$page = 1;
			}
			$per_page = 10;//每页显示20条
			if($page<=1){$page=1;}//最大值还没有设置,在后面的db结果设置
			$start_from = ($page-1)*$per_page;
		}


		require_once ("./includes/configure.php");
			require_once ("./includes/database.php");
			$db = Database :: Connect();

				$sql = "select * from zufang"; //默认0为出租

				$where_sql = " where type=1 ";
			if($_GET['cond'] == 'jitui'){
			   $where_sql .= " and jitui=1 "; //默认0为出租
			}

			if($_GET['kw']){
				$kw = $_GET['kw'];
				$where_sql .= " and (dizhi like '%$kw%' or biaoti like '%$kw%' or jieshao like '%$kw%')";
			}

			if($_GET['quyu']){
				$where_sql .= " and quyu=".$_GET['quyu']." ";
			}
			if($_GET['quyu2']){
				$where_sql .= " and quyu2=".$_GET['quyu2']." ";
			}
			if($_GET['shoujia']){
				$shoujiacond = $_GET['shoujia'];
				if(strpos($shoujiacond,"<")!==false)
				{
					$where_sql .= " and jiage".$shoujiacond;
				}else if(strpos($shoujiacond,">")!==false){
					$where_sql .= " and jiage".$shoujiacond;
				}
				else{
					$range = explode("-",$shoujiacond);
					$where_sql .= " and jiage>".$range[0]." and jiage<".$range[1];
				}
			}


			if($_GET['mianji']){
				$mianjicond = $_GET['mianji'];
				if(strpos($mianjicond,"<")!==false){
					$where_sql .= " and mianji<".$mianjicond;
				}else if(strpos($mianjicond,"<")!==false){
					$where_sql .= " and mianji".$mianjicond;
				}
				else{
					$range = explode("-",$mianjicond);
					$where_sql .= " and mianji>".$range[0]." and mianji<".$range[1];
				}
			}

			if($_GET['huxing']){
				$huxingcond_shi = $_GET['huxing'];
				$where_sql .= " and huxing like '".$huxingcond_shi."|%' ";
			}
			if($_GET['leixing']){
				$leixingrow = $db->GetSingleRow("select this_id from configuration where configuration.`key` = 'zufang_leixing' and value=".$_GET['leixing']);
               	$leixing =  $leixingid = $leixingrow->this_id;
				$where_sql .= " and leixing=".$leixingid;
			}

			if($_GET['fangshi'] == "zz"){
				$where_sql .= " and zulin = '整租'";
			}
			else if ($_GET['fangshi'] == "hz"){
				$where_sql .= " and zulin = '合租'";
			}

			$sql .= $where_sql;
			if($_GET['sort']){
				$sort = $_GET['sort'];
				$sql .= " order by ".$sort." limit $start_from,$per_page";
			}
			else{
             $sql.=" order by time desc limit $start_from,$per_page";
			}


			if(true){
			//page_2
				$count_sql = "select count(*) from zufang  $where_sql";

				$count_result = $db->GetResultSet($count_sql);
				while ($count_row = mysql_fetch_array($count_result)) {
					$total_item = $count_row[0];
				}
				$max_page = ceil($total_item/$per_page);
			}

			$chushourows = $db->GetResultSet($sql);

?>
<div class="main_content">


	<div class="listleft">
	<div class="search-result2">
	<div class="quicktabs">
	<ul>

		<li  class="<?php echo $_GET['cond']==='jitui'?"":"slt"?>"><span><a href="ershoufang.php"
			rel="nofollow" >全部房源</a></span></li>

		<li  class="<?php echo $_GET['cond']==='jitui'?"slt":""?>"><span><a href="ershoufang.php?cond=jitui"
			rel="nofollow"   style="padding: 0px 15px;">急售房源</a></span></li>
		<!--<li class="map"><span class="map-ion"></span><span><a
			href="#" >地图模式</a></span></li>-->
	</ul>
<!--	<div class="simple_m_p">
	<div class="simple_multipage">

	<div class="pagelink noprexpage">&nbsp;</div>

	<div class="current">1/26646</div>

	<div class="pagelink nextpage"><a
		href="#/sale/p2" title="下一页">下一页</a></div>

	</div>
	</div>-->
	</div>
	<div class="search_bottom">
	<div style="float: left;">
	<div class="totalnum" style="margin-top: 7px;">房客网找到 <strong><?php echo $total_item?></strong>套符合要求的房子</div>
	<div class="quick_btn"></div>
	</div>

	<div class="sortby"><span
		style="float: left; line-height: 20px; line-height: 24px\9;">排序：</span>
	<div id="selectorder_id"><a href="javascript:void(0);" class="select"><span
		class="select_item"><span class="txt">默认排序</span><span class="icon">&nbsp;</span></span>
	<!--[if IE 7]><!--></a><!--<![endif]--> <!--[if IE 8]><!--><!--<![endif]-->
	<!--[if !IE]>--><!--<![endif]--> <!--[if lte IE 6]>
	                    <iframe src="" style="position:absolute;visibility:inherit; top:0px; left:-1px; width:99px; height:105px;z-index:-1;opacity:.0;filter:alpha(opacity=0); -moz-opacity:0;"></iframe>
	                    <table><tr><td><![endif]-->
	<ul>
		<li class="selected"><a href="<?php echo  deleteRepeatVar($current_url,'sort').'&sort=time desc' ?>"
			class="select_list" rel="nofollow">默认排序</a></li>
		<li><a href="<?php echo deleteRepeatVar($current_url,'sort').'&sort=mianji desc' ?>" class="select_list"
			rel="nofollow">面积从大到小</a></li>
		<li><a href="<?php echo  deleteRepeatVar($current_url,'sort').'&sort=mianji asc' ?>" class="select_list"
			rel="nofollow">面积从小到大</a></li>
		<li><a href="<?php echo  deleteRepeatVar($current_url,'sort').'&sort=jiage desc' ?>" class="select_list"
			rel="nofollow">总价从高到低</a></li>
		<li><a href="<?php echo  deleteRepeatVar($current_url,'sort').'&sort=jiage asc' ?>" class="select_list"
			rel="nofollow">总价从低到高</a></li>
	</ul>
	<!--[if lte IE 6]></td></tr></table></a><![endif]--></div>

	<!--<a href="#/sale/o4" rel="nofollow">总价</a><a
		href="#/sale/o2" rel="nofollow">面积</a>
		-->
		</div>

	</div>
	</div>

	<div style="margin: 10px 0px 5px 15px"></div>
	<div class="listing">
	<ol id="list_body">
		<?php



			while ($row = mysql_fetch_array($chushourows)) {
				$id = $row['id'];
				$biaoti = $row['biaoti'];
				$xiaoquid = $row['xiaoqu'];
				$dizhi = $row['dizhi'];
				$jiage = $row['jiage'];
				$huxing = $row['huxing'];
				$huxing = explode('|', $huxing);
				$huxing_shi = $huxing[0] . '室';
				$huxing_ting = $huxing[1] . '厅';
				$huxing_wei = $huxing[2] . '卫';
				$huxing = $huxing_shi . $huxing_ting . $huxing_wei;
				$zhuangxiu = $row['zhuangxiu'];
				$louceng = $row['louceng'];
				$chuzufangshi = $row['zulin'];
				$jitui = $row['jitui'];
				$xintui = $row['xintui'];
				$duotu = $row['duotu'];
				$lianxiren = $row['lianxiren'];
				$fangling = $row['fangling'];
				$time = $row['time'];
				$tupian = $row['tupian'];
	            $tupian = explode(";",$tupian);
	               if(count($tupian)>=5) $duotu=1;

?>
		<li id="li_prop_1" class="">
		<div class="property2" id="prop_1">
		<div class="photo"><a
			href="fangwu.php?id=<?php echo $id?>" class="photo"
			title="<?php echo $biaoti?>" alt="<?php echo $biaoti?>"><img
			class="thumbnail" id="prop_1_a"
			src="<?php echo './'.$tupian[0] ?>"
			alt="<?php echo $biaoti?>" width="100" height="75" onerror="this.src='./images/avatar.gif'"></a></div>
		<div class="details">
		<h4><a id="prop_name_qt_prop_1"
			href="fangwu.php?id=<?php echo $id?>"
			title="<?php echo $biaoti?>"><?php echo $biaoti?>
		</a>

		<?php if($duotu == 1) {?><img src="images/icon-more-28x16.gif" style="”vertical-align:middle”">	<?php }?>
		</h4><span style="color:#FF6600;">(个人)</span>
		<address><?php echo $dizhi ?></address>
		<p id="prop_detail_qt_prop_1">
		<?php echo $huxing.' '.$chuzufangshi.' '.$zhuangxiu.'  楼层: '.$louceng.'  房龄: '.$fangling ?>	</p>

		<p class="broker"><?php echo $lianxiren?></p>
		</div>
		<div id="prop_price_qt_prop_1" class="price"><strong><?php echo $jiage?></strong> 万 </div>

		<div class="tags"><span><?php echo time_tran($time);?></span><br/>
		<span>
			<?php
				if($db->isFavorites(2,$id)){
			?>
				<a href="shoucang.php?action=cancle&sc_type=2&dx_id=<?php echo $id;?>" id="cz_favorite">
					<img id="shoucang" style="cursor:pointer" title="取消收藏"
						onmouseover="javascript:this.src='images/star_none.ico';"
						onmouseout="javascript:this.src='images/fav.ico';"
						width="20" src="images/fav.ico">
				</a>
			<?php
				}else{
			?>
				<a href="shoucang.php?sc_type=2&dx_id=<?php echo $id;?>" title="收藏信息" id="cz_favorite">
					<img id="shoucang" style="cursor:pointer" title="收藏"
						onmouseover="javascript:this.src='images/fav.ico';"
						onmouseout="javascript:this.src='images/star_none.ico';"
						width="20" src="images/star_none.ico">
				</a>
			<?php
				}
			?>
		</span>
		</div>
		</div>
		<div class="advlogo" id="advlogo_85911081"></div>
		</li>
		<?php }?>

	</ol>
	<div class="multipage-div">
	<div class="contain">
			<?php if(true){
	//page_3
?>
<div class="multipage">

	<?php
		if($page!=1){
			echo '<a class="prv" href="'.deleteRepeatVar($current_url,'page').'&page='.($page-1).'"><span>上一页</span></a>';
		}
		if($max_page>10){
			$ind = $page-5;
		}
		if($ind<=0){
			$ind=1;
		}
		$page_show_total = 10;//最多显示10页
		for(;$ind<=$max_page;$ind++){
			if($ind==$page){
				echo '<strong><span>'.$ind.'</span></strong>';
			}else{
				echo '<a href="'.deleteRepeatVar($current_url,'page').'&page='.$ind.'"><span>'.$ind.'</span></a>';
			}
			$page_show_total--;
			if($page_show_total==0){
				break;
			}
		}
		if($page!=$max_page && $max_page!=0){
			echo '<a class="next" href="'.deleteRepeatVar($current_url,'page').'&page='.($page+1).'"><span>下一页</span></a>';
		}

		if($total_item==0){
				echo "<strong><span>没有找到符合的信息！</span></strong>";
		}
	?>

</div>
<?php } ?>


<?php

		$db->Close();

		?>
	</div>
	<div class="result">房客网找到 <b><?php echo $total_item?></b> 套符合要求的房子</div>
	</div>
	</div>
	</div>

</div>
